#ifndef EXPANSIONBOARDCOMM_H_
#define EXPANSIONBOARDCOMM_H_

/************************************************************************************
*	Copyright Paxs Electronics 2012													*
*   All Rights Reserved																*
*   The Copyright symbol does not also indicate public availability or publication.	*
* 																					*
* 								PAXS ELECTRONICS									*
* 																					*
* - Driver:   			Function to transmit info to Expansion Board				*
* 																					*
* - Compiler:           Code Composer Studio (Licensed)								*
* - Supported devices:  All Stellaris Family Cortex-M3.								*
* - AppNote:																		*
*																					*
* 	Created by: 		Juan Francisco Gomez Ruiz									*
*   Date Created: 		20 - Apr - 2012												*
*   Contac				pacoduz@gmail.com											*
* 																					*
* 	Description: 		Provide a set of function to make communication to the		*
* 						Expansion Board												*
*   Device supported and tested: - LM3S5749 - LM3S3748 -							*
* 																				2012*
*************************************************************************************

*************************************************************************************
* 	Revision History:
*
*   Date          CP#           Author
*   MM-DD-YY      XXXXX:1       Initials   Description of change
*   -----------   -----------   --------   ------------------------------------
*    04-20-12      	1.0             JFGR	Initial version. 

*************************************************************************************
* 	File/
* 
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
*  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
*  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
*  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
*  DEALINGS IN THE SOFTWARE.
* 
*/

	#include "inc/hw_ints.h"
	#include "inc/hw_memmap.h"
	#include "inc/hw_sysctl.h"
	#include "inc/hw_types.h"
	#include "driverlib/gpio.h"
	#include "driverlib/sysctl.h"
	#include "driverlib/interrupt.h"
	#include "inc/hw_ssi.h"
	#include "driverlib/ssi.h"
	#include "DataIntegrity.h"
/******************************************************************************
*							GLOBAL MACRO DEFINITIONS
******************************************************************************/
	#define PS2			0
	#define WIFI		1
	#define CONTROLLER	PS2
	#if CONTROLLER == PS2
	#define QXCDATA_LENTG	1
	#endif
	
	//////////////////////////////////
	//		SSI0 MODULE CONFIG		//
	//////////////////////////////////
	#define SSI0_MODULE					0
	#define SSI0_FRAME_FORMAT			(SSI_FRF_MOTO_MODE_0)
	#define SPI0_INTERRUPTION			0			//0 - Interruption Disable, 1 - Interruption Enable
	#define SPI0_INTERRUPTION_SERVICE	SSI_RXFF	//Type pof interruption

	
	//////////////////////////////////
	//		SSI1 MODULE CONFIG		//
	//////////////////////////////////
	#define SSI1_MODULE					1
	#define SSI1_FRAME_FORMAT			(SSI_FRF_MOTO_MODE_0)
	#define SPI1_INTERRUPTION			1			//0 - Interruption Disable, 1 - Interruption Enable
	#define SPI1_INTERRUPTION_SERVICE	SSI_RXFF	//Type pof interruption
	
	#define ATTENTION_PORT				GPIO_PORTF_DATA_R
	#define ATTENTION_PIN				0x10
	
	/*********************		INFO ONLY		**************************/
//	#define SSI_FRF_MOTO_MODE_0     0x00000000  // Moto fmt, polarity 0, phase 0
//	#define SSI_FRF_MOTO_MODE_1     0x00000002  // Moto fmt, polarity 0, phase 1
//	#define SSI_FRF_MOTO_MODE_2     0x00000001  // Moto fmt, polarity 1, phase 0
//	#define SSI_FRF_MOTO_MODE_3     0x00000003  // Moto fmt, polarity 1, phase 1
//	#define SSI_FRF_TI              0x00000010  // TI frame format
//	#define SSI_FRF_NMW             0x00000020  // National MicroWire frame format
//
//	#define SSI_MODE_MASTER         0x00000000  // SSI master
//	#define SSI_MODE_SLAVE          0x00000001  // SSI slave
	/*********************************************************************/
	
	//////////////////////////////////
	//			PACKAGE HEADER		//
	//////////////////////////////////
	#define HEADER1			'Q'
	#define HEADER2			'X'
	#define HEADER3			'C'
	#define HEADER_LENGTH	3
	#define DATA_LENGTH		8	//1 byte of info (from Master to Slave), 4 dummy bytes to get the rest of info from slave 
								//and 1 checksum byte
	#define DATA_POSITION	4
	#define PACKAGE_LENGTH	10

/******************************************************************************
*   Local Type Definitions
******************************************************************************/

/******************************************************************************
*   Local Function Declarations
******************************************************************************/

/******************************************************************************
*   Global Variable Definitions
******************************************************************************/
	extern unsigned char ExpansionBoardData[DATA_LENGTH-HEADER_LENGTH];	//Data Buffer received from Expansion Board 
	extern unsigned char QuaXcopterData[DATA_LENGTH-HEADER_LENGTH];		//Data Buffer to be sent to Expansion Board 
	extern unsigned char SPITXBuffer[PACKAGE_LENGTH];		//Buffer that contains the Package to be send by SPI module	
	extern unsigned char SPIRXBuffer[PACKAGE_LENGTH];		//Buffer that contain the Package received by SPI module
	extern volatile char PackageDataCounter;					//Number of byte received from the SPI Slave
	typedef struct						//Structure to handle State Machin, that controls:
	{									// Reading and Writting of IMU Sensors.			 
		unsigned char ActualState;
		unsigned char NextState;
	}SPISM;
/******************************************************************************
*   Static Variable Definitions
******************************************************************************/

/******************************************************************************
*   Global and Static Function Definitions
******************************************************************************/
	void VfnSSIModuleInitialization(unsigned char Module,unsigned long Frequency,unsigned char DataSize);
	void VfnAttentionPin(void);
	unsigned char VfnExpansionBoardComm(void);
	unsigned char VfnSPIReadRXBuffer( void );
	unsigned char VfnSPIValidateData( void );
#endif /*EXPANSIONBOARDCOMM_H_*/
